<template>
  <div class="query-list">
    <nanning-screen-search @on-input-search="onInputSearch" :searchValue="searchValue" :placeholderValue="placeholderValue" @on-click-input="onClickInput"></nanning-screen-search>
    <div class="query-list-content">
      <!-- <div class="query-list-content-title">共152条数据</div> -->
      <div class="swiper" :options="swiperOption" v-show="dataList.length > 0">
        <div v-for="(item, index) in dataList" :key="index" class="swiper-slide">
          <div :class="['query-list-content-item', activeCode === item.id ? 'active' : '']" @click="onChangeItem(item.id)">
            <div class="item">
              <div class="item-title">
                <div>{{ item.name }}</div>
                <div class="type">{{ item.typeName }}</div>
              </div>
              <div class="item-content">
                <div class="item-content-time">时间：{{ item.time }}</div>
                <div class="item-content-time">地点：{{ item.address }}</div>
              </div>
            </div>
          </div>
          <screen-load-more :loadMoreVisible="loadMoreVisible" :loadMoreType="loadMoreType"></screen-load-more>
        </div>
        <div class="swiper-scrollbar" slot="scrollbar"></div>
      </div>
      <div class="nodata-container" v-show="dataList.length === 0">
        <div class="nodata-img">
          <img src="../../../../../assets/images/no-data.png" alt="" />
        </div>
      </div>
    </div>
  </div>
</template>

<script lang="ts">
import { Component, Vue } from 'vue-property-decorator'
import { Swiper, SwiperSlide } from 'vue-awesome-swiper'
import Bus from 'utils/eventBus'
enum LoadMoreType {
  none = 'none',
  loading = 'loading'
}
@Component({
  name: 'query-list',
  components: {
    Swiper,
    SwiperSlide
  }
})
export default class QueryList extends Vue {
  private loadMoreVisible = false

  private loadMoreType: LoadMoreType = LoadMoreType.none
  private loadStatus = true
  private dataList: any = [
    // {
    //   id: '1',
    //   name: '菜刀',
    //   time: '2021-12-23',
    //   address: '青秀区星湖路南二里2号',
    //   typeName: '管制刀具',
    //   imgUrl: require('assets/images/situational-awareness/type1.png')
    // },
    // {
    //   id: '2',
    //   name: '高仿枪支',
    //   time: '2021-11-20',
    //   address: '青秀区民族大道48号',
    //   typeName: '管制刀具',
    //   imgUrl: require('assets/images/situational-awareness/type1.png')
    // },
    // {
    //   id: '3',
    //   name: '烟花爆竹',
    //   time: '2021-12-23',
    //   address: '青秀区新竹路38-18号',
    //   typeName: '易燃品',
    //   imgUrl: require('assets/images/situational-awareness/type2.png')
    // },
    // {
    //   id: '3',
    //   name: '硫酸',
    //   time: '2021-12-23',
    //   address: '青秀区新竹路38号',
    //   typeName: '腐蚀物品',
    //   imgUrl: require('assets/images/situational-awareness/type2.png')
    // }
  ]

  private activeCode = '1'

  private searchValue = ''

  private placeholderValue = '请输入违禁品'

  private swiperOption = {
    direction: 'vertical',
    // autoplay: {
    //   delay: 2500,
    //   disableOnInteraction: false
    // },
    slidesPerView: 'auto',
    freeMode: true,
    scrollbar: {
      el: '.swiper-scrollbar'
    },
    mousewheel: true
  }

  private onChangeItem(value: any) {
    this.activeCode = value
  }

  private onInputSearch(value: any) {
    this.searchValue = value
  }

  private onClickInput(value: any) {
    Bus.$emit('openProhibitedSearchPop', value)
  }

  mounted() {
    this.onReachBottom()
  }

  created() {
    Bus.$on('onClickProhibitedSearch', (value: any) => {
      console.log('搜索框改变了---右侧盒子', value)
    })
  }

  destroyed() {
    // @ts-ignore
    document.querySelector('.swiper').removeEventListener('scroll', (e: any) => {
      const { scrollHeight, scrollTop, clientHeight } = e.target
      if (clientHeight + scrollTop >= scrollHeight) {
        this.loadMoreVisible = true
      }
    })
  }

  onReachBottom() {
    // @ts-ignore
    document.querySelector('.swiper').addEventListener('scroll', (e: any) => {
      const { scrollHeight, scrollTop, clientHeight } = e.target
      if (clientHeight + scrollTop >= scrollHeight) {
        this.loadMoreVisible = true
      }
    })
  }
}
</script>

<style lang="scss" scoped>
.query-list {
  box-sizing: border-box;
  width: 100%;
  height: calc(100% - 50px);
  padding: 30px 20px 24px 22px;
  font-family: 'PingFang Regular';
  &-content {
    box-sizing: border-box;
    width: 100%;
    height: calc(100% - 42px);
    padding-top: 30px;
    &-title {
      box-sizing: border-box;
      width: 100%;
      height: 25px;
      line-height: 25px;
      text-align: left;
      font-size: 14px;
      font-family: 'PingFang Regular';
      color: rgba(255, 255, 255, 0.6);
      padding-left: 15px;
    }
    .nodata-container {
      width: 100%;
      height: calc(100% - 42px - 56px - 100px);
      display: flex;
      align-items: center;
      justify-content: center;
      .nodata-img {
        width: 249px;
        height: 172px;
      }
    }
    .swiper {
      box-sizing: border-box;
      width: 100%;
      height: calc(100% - 25px);
      overflow-y: auto;
      &::-webkit-scrollbar {
        /*滚动条整体样式*/
        width: 6px; /*高宽分别对应横竖滚动条的尺寸*/
        height: 1px;
      }
      &::-webkit-scrollbar-thumb {
        /*滚动条里面小方块*/
        border-radius: 10px;
        box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2);
        background: #114da7;
      }
      &::-webkit-scrollbar-track {
        /*滚动条里面轨道*/
        box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2);
        border-radius: 10px;
        background: #061836;
      }
      .swiper-slide {
        box-sizing: border-box;
        width: 100%;
        height: calc(100% / 5.8);
        // height: calc(100% / 7 - 7px);
        // margin-bottom: 7px;
      }
      .query-list-content-item {
        position: relative;
        box-sizing: border-box;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        width: 100%;
        height: 100%;
        background: rgba(16, 75, 164, 0.22);
        font-family: 'PingFang Regular';
        padding: 0 20px;
        .item {
          box-sizing: border-box;
          width: 100%;
          height: 100%;
          border-bottom: 1px dotted rgba(130, 152, 217, 0.8);
          &-title {
            display: flex;
            align-items: center;
            height: 46px;
            div:nth-child(1) {
              font-size: 18px;
              font-family: 'PingFang Regular';
              font-weight: 500;
              color: #ffffff;
              margin-right: 15px;
            }
            .type {
              height: 24px;
              line-height: 24px;
              font-size: 14px;
              color: #ffffff;
              padding: 0 9px;
              border-radius: 12px;
              background: #b2620b;
            }
          }
          &-content {
            display: flex;
            flex-direction: column;
            align-items: flex-start;
            color: #8da5eb;
            font-size: 16px;
          }
        }
      }
      .active {
        background: rgba(16, 75, 164, 0.32);
        background-size: 100% 100%;
      }
      .swiper-scrollbar ::v-deep .swiper-scrollbar-drag {
        background: rgba(16, 75, 164, 0) !important;
      }
    }
  }
}
</style>
